package com.pets.springboot_petshop.controller;

import com.pets.springboot_petshop.entity.Membershiptype;
import com.pets.springboot_petshop.pojo.Result;
import com.pets.springboot_petshop.service.MembershiptypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Membershiptype")
public class MembershiptypeController {
    @Autowired
    private MembershiptypeService membershiptypeService;
    //查询
    @GetMapping("/selectMembershiptype")
    public Result selectMembershiptype(@RequestParam  String name) {
        List<Membershiptype> membershiptypes = membershiptypeService.selectMembershiptype(name);
        if (membershiptypes != null) {
            return Result.success(membershiptypes);
        }else {
            return Result.error("获取失败");
        }
    }
    //查询所有
    @GetMapping("/findAll")
    public Result findAll() {
        List<Membershiptype> membershiptypeList = membershiptypeService.findAll();
        if (membershiptypeList != null) {
            return Result.success(membershiptypeList);
        }else {
            return Result.error("获取失败");
        }
    }
    //新增
    @PostMapping("/addMembershiptype")
    public Result addMembershiptype(@RequestBody Membershiptype membershiptype) {
        if (membershiptypeService.addMembershiptype(membershiptype) > 0) {
            return Result.success("新增成功");
        }else {
            return Result.error("新增失败");
        }
    }
    //删除
    @PostMapping("/deleteMembershiptypeById")
    public Result deleteMembershiptypeById(@RequestParam int id) {
        if (membershiptypeService.deleteMembershiptypeById(id) > 0) {
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
    //修改
    @PostMapping("updateMembershiptypeById")
    public Result updateMembershiptypeById(@RequestBody Membershiptype membershiptype) {
        if (membershiptypeService.updateMembershiptypeById(membershiptype) > 0) {
            return Result.success("修改成功");
        }else{
            return Result.error("修改失败");
        }
    }
}
